<template>
  <div class="about">
    <h1>这是我的主页</h1>
    <el-button type="primary" @click="aaa">按钮</el-button>

    <template>
      <el-input v-model="text" placeholder="请输入内容"></el-input>
      <el-button type="success" @click="handleSpeak">开始播报</el-button>
      <el-button type="success" @click="handleStop">停止播报</el-button>
    </template>
  </div>
</template>
<script>
//启用文本
const synth = window.speechSynthesis;
const msg = new SpeechSynthesisUtterance();
export default {
  data() {
    return{
      text:""

    }
  },

  methods: {
    aaa() {
      this.axios.get("http://localhost:8005/entrust/list").then(res => {
      })
    },
    playVoice() {
      this.handleSpeak()
    },
    handleSpeak(text) {
      //内容
      msg.text = this.text;
      // 使用的语言：中文
      msg.lang = 'zh-CN';
      //声音音量
      msg.volume = 1;
      //语速
      msg.rate = 1;
      //音高
      msg.pitch = 1;
      //开始播放
      synth.speak(msg);
    },
  //  语音停止
    handleStop(e) {
      msg.text = 0;
      msg.lang = "zh-CN";
      //取消这次语言播报
      synth.cancel(msg);
    },
  }
}
</script>